package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * @description: 查询购物车数据
     * @author: tanbobin
     * @date: 2024/6/5 20:35
     * @param:
     * @param shoppingCart
     * @return:
     * @return java.util.List<com.sky.entity.ShoppingCart>
     **/
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * @description: 更新数量
     * @author: tanbobin
     * @date: 2024/6/5 20:46
     * @param: 
     * @param cart
     * @return:
     **/
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart cart);

    /**
     * @description: 添加购物车
     * @author: tanbobin
     * @date: 2024/6/5 21:10
     * @param: 
     * @param shoppingCart
     * @return:
     **/
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)" +
            "    values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * @description: 清空购物车
     * @author: tanbobin
     * @date: 2024/6/5 22:14
     * @param:
     * @param shoppingCart
     * @return:
     **/
    @Delete("delete from  shopping_cart where user_id = #{userId}")
    void delete(ShoppingCart shoppingCart);

    /**
     * @description: 根据购物车id删除数据
     * @author: tanbobin
     * @date: 2024/6/5 22:26
     * @param:
     * @param id
     * @return:
     **/
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);
}
